package com.yunji.cabinet.service.impl;

import com.yunji.cabinet.context.convert.UpgradeInfoConvert;
import com.yunji.cabinet.bo.UpgradeInfoListBO;
import com.yunji.cabinet.dao.IUpgradeInfoDao;
import com.yunji.cabinet.domain.UpgradeInfoDO;
import com.yunji.cabinet.params.UpgradeInfoParam;
import com.yunji.cabinet.service.IUpgradeInfoService;
import com.yunji.cabinet.vo.UpgradeInfoVO;
import com.yunji.common.base.IModifyStatusBaseBO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UpgradeInfoServiceImpl implements IUpgradeInfoService {

    @Resource
    private IUpgradeInfoDao upgradeInfoDao;

    @Override
    public boolean saveBatch(List<UpgradeInfoDO> infoList) {
        return upgradeInfoDao.saveBatch(infoList);
    }

    @Override
    public boolean checkWaitInfo(String taskCode) {
        return upgradeInfoDao.checkWaitInfo(taskCode);
    }

    @Override
    public boolean startTask(Long infoId) {
        return upgradeInfoDao.startTask(infoId);
    }

    @Override
    public List<UpgradeInfoVO> searchVO(UpgradeInfoListBO bo) {
        List<UpgradeInfoDO> list =  upgradeInfoDao.search(bo);
        return UpgradeInfoConvert.domainTOVOList(list);
    }

    @Override
    public Integer countNumsByStatus(String taskCode, Integer status) {
        return upgradeInfoDao.countNumsByStatus(taskCode,status);
    }

    @Override
    public List<UpgradeInfoVO> searchPageList(UpgradeInfoParam param) {
        List<UpgradeInfoDO> list = upgradeInfoDao.searchPageList(param);
        return UpgradeInfoConvert.domainTOVOList(list);
    }

    @Override
    public boolean modifyWhetherRetry(Long infoId, Integer newStatus, ArrayList<Integer> oldStatus) {
        return upgradeInfoDao.modifyWhetherRetry(new IModifyStatusBaseBO() {
            @Override
            public Object getId() {
                return infoId;
            }

            @Override
            public Integer getNewStatus() {
                return newStatus;
            }

            @Override
            public List<Integer> getOldStatus() {
                return oldStatus;
            }
        });
    }

    @Override
    public boolean modifyStatus(Long infoId, Integer code, ArrayList<Integer> integers) {
        return false;
    }

    @Override
    public boolean checkCancel(Long infoId) {
        return upgradeInfoDao.checkCancel(infoId);
    }

    @Override
    public boolean closeTaskByTaskCode(String taskCode) {
        return upgradeInfoDao.closeTaskByTaskCode(taskCode);
    }

    @Override
    public List<UpgradeInfoDO> getUpgradeInfoList(UpgradeInfoListBO infoListBO) {
        return upgradeInfoDao.getUpgradeInfoList(infoListBO);
    }
}
